package com.example.myframe;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.example.myprint.PrintApp;
import com.example.myprint.utils.XmlUtil;
import com.a.lib_bean.api.Url;
import com.a.lib_bean.bean.Employee;
import com.a.lib_bean.consts.Const;
import com.a.lib_network.http.RequestHandler;
import com.a.lib_utils.TipUtil;
import com.tencent.mmkv.MMKV;

/**
 * 初始化了网络配置、网络状态监听、打印模块、distDeptID
 */
public abstract class DistDeptApp extends BaseNetApp {

    private static Employee employee;//用户信息



    public static Employee getEmployee() {
        return employee;
    }

    public static void setEmployee(Employee employee) {
        DistDeptApp.employee = employee;
    }

    public MMKV kv;

    @Override
    public void onCreate() {
        super.onCreate();
        PrintApp.init(this);//打印模块初始化
        if (!XmlUtil.hadTag("DistDeptID")) {
            XmlUtil.writeFileSdcard("DistDeptID", "88");
        }
        distDeptID = XmlUtil.readFileSdcard("DistDeptID");
        kv = MMKV.defaultMMKV();
        String ip = kv.decodeString(Const.getKV_KEY_IP(), Url.host2);
        Url.host = "http://" + ip +":8181";
        LogUtils.i(ip+Url.host);
        setNetConfig("http://" + ip +":8181", 6, new RequestHandler(this));
        NetworkUtils.registerNetworkStatusChangedListener(new NetworkUtils.OnNetworkStatusChangedListener() {
            @Override
            public void onDisconnected() {
                TipUtil.toast("网络已断开，请检查网络");
            }

            @Override
            public void onConnected(NetworkUtils.NetworkType networkType) {
                TipUtil.toast("网络已连接");
            }
        });
    }
}
